package com.myproject;

public class WaitTest {

    public static String name = "tom";

    public static void main(String[] args) {

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {

                Thread thread = Thread.currentThread();
                System.out.println(thread.getName()+" start");
                try {
                    name.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(thread.getName()+" end");
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {

                Thread thread = Thread.currentThread();
                System.out.println(thread.getName()+" start");
                try {
                    name.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(thread.getName()+" end");
            }
        });

        thread1.start();
        thread2.start();
    }
}
